package part1.api.io.mytest;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * 缓冲流
 */
public class BRDemo {
    public static void main(String[] args) {
        try (
                FileOutputStream fos = new FileOutputStream("bw.txt");
                OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
                BufferedWriter bw = new BufferedWriter(osw);
                PrintWriter pw = new PrintWriter(bw)
        ) {
            pw.println("你好中国");
            pw.println("我爱世界");
        } catch (Exception e) {

        }

        System.out.println("缓冲流写出成功");

        try (
                FileInputStream fis = new FileInputStream("bw.txt");
                InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
                BufferedReader br = new BufferedReader(isr)
        ) {
            String line;
            while ((line = br.readLine()) !=null){
                System.out.println(line);
            }
        } catch (Exception e) {

        }

    }
}
